﻿<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<TvGuide.UI.Models.ProgramData>" %>

<div class="Category_Widget_Main">
<span class="catWidgetTitle">Նշել՝</span>
<div id="catGroup">
<% int num = 0; %>
<% foreach (var catlist in Model.Catlist)
   {
       num++;
%>
  <% 
       if (num == null)
       {
  %>

  <div id="Div1" class="Category_Widget_CatContainer Category_Widget_CatContainer_last" onclick="ProgCatchangediv(this)"><input type="checkbox" name="<%: catlist.color  %>" value="<%: "Category_"+ catlist.CatId %>" onclick="ProgCatchange(this)" class="ProgCatCheckbox" />
  <span  style="background-color: <%:catlist.color  %>; padding: 2px 3px;"> <%: catlist.CatDispName%> </span> 
  </div>

  <%
       }  
   %>

    <%
       else
       {
   %>


 <div  class="Category_Widget_CatContainer" ><input type="checkbox" name="<%: catlist.color  %>" value="<%: "Category_"+ catlist.CatId %>"  onclick="ProgCatchange(this)" class="ProgCatCheckbox" />
  <span id="<%: "Category_"+ catlist.CatId %>" onclick="ProgCatchangediv(this)" style="background-color: <%:catlist.color  %>; cursor:pointer; padding: 2px 3px;"> <%: catlist.CatDispName%> </span> 
  </div>

  <%
       }  
   %>

<%
   }
%>
</div>
</div>

<script type="text/javascript">

    function ProgCatchangediv(obj) {
        var allchbx = document.getElementsByClassName('ProgCatCheckbox');
        for (var ind = 0; ind < allchbx.length; ind++) 
            if (allchbx[ind].value == obj.id) {
                if (allchbx[ind].checked == true)
                    allchbx[ind].checked = false;
                else
                    allchbx[ind].checked = true;
                ProgCatchange(allchbx[ind]);
                break;
            }
    }

    function ProgCatchange(obj) {
       
        var allprogs = document.getElementsByClassName('progcathiden');

        for (var ind = 0; ind < allprogs.length; ind++) {
            if (allprogs[ind].value == obj.value) {


                if (obj.checked == true) {
                    var ch1 = document.getElementsByClassName(obj.value);
                    for (var ind = 0; ind < ch1.length; ind++)
                        ch1[ind].style.background = obj.name;
                    break;
                }
                if (obj.checked == false) {
                    var ch1 = document.getElementsByClassName(obj.value);
                    for (var ind = 0; ind < ch1.length; ind++)
                        ch1[ind].style.background = "";
                    break;
                }
            }
            
        }
        
    }

    function ProgCatChbxChecker() {

        var allchbx = document.getElementsByClassName('ProgCatCheckbox');
        for (var ind = 0; ind < allchbx.length; ind++)
            if (allchbx[ind].checked == true)
                ProgCatchange(allchbx[ind]);
            
    }

</script>